package com.example.manager.controller;

import com.example.manager.domain.R;
import com.example.manager.domain.SysDept;
import com.example.manager.domain.SysPost;
import com.example.manager.domain.SysUser;
import com.example.manager.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
//部门表CRUD
@RequestMapping("/slm/dept")
@RestController
public class SysDeptController {

    @Autowired
    SysDeptService sysDeptService;

    @GetMapping("/find")
    public R<List<SysDept>> findDeptC(
            @RequestParam String deptName,
            @RequestParam String status
    ){
        System.out.println(status);
        List<SysDept> c = sysDeptService.findC(0,deptName, status);
        return R.success(c);
    }

    @GetMapping("/findD")
    public R<List<SysDept>> findDeptD(){
        List<SysDept> c = sysDeptService.findD(0);
        return R.success(c);
    }

    @PostMapping("/insert")
    public R<String> insert(@RequestBody SysDept sysDept,@RequestAttribute("user") SysUser users){
        sysDept.setCreateBy(users.getUsername());
        sysDept.setCreateTime(new Date());
        sysDeptService.save(sysDept);
        return R.success("添加成功");
    }

    @PostMapping("/insertT")
    public R<String> insertT(@RequestBody SysDept sysDept,@RequestAttribute("user") SysUser users){
        sysDept.setCreateBy(users.getUsername());
        sysDept.setCreateTime(new Date());
        sysDeptService.save(sysDept);
        return R.success("添加成功");
    }

    @PutMapping("/update")
    public R<String> update(@RequestBody SysDept sysDept,@RequestAttribute("user") SysUser users){
        sysDept.setUpdateBy(users.getUsername());
        sysDept.setUpdateTime(new Date());
        sysDeptService.updateById(sysDept);
        return R.success("修改成功");
    }

}
